﻿<!-- #include file="../ding.asp" -->
<!-- #include file="../mymin.asp" -->
<!--#include file="upload.inc"-->
<%Call Head2()%>
<title>WAP2.0上传WML文件</title>
</head>
<body>
<%
' 忽略所有错误
on error resume next
Server.ScriptTimeOut = 1800
dim constPath,mypath
mypath=server.mappath("wmlupfile.asp")
constPath=replace(mypath,"wmlupfile.asp","")
dim upload,oFile,formName,SavePath,filename,fileExt,oFileSize,sizes
dim EnableUpload
dim arrUpFileType
dim ranNum
dim msg,FoundErr,MaxFileSize
MaxFileSize="5120"'最大上传文件，以KB为单位
msg=""
FoundErr=false
EnableUpload=true
dim strMonth,strDay
dim content

set upload=new upfile_class '建立上传对象
upload.GetData(MaxFileSize*1024)   '取得上传数据,限制最大上传5M
if upload.err > 0 then  '如果出错
	select case upload.err
		case 1
			msg= "请先选择你要上传的文件！"
		case 2
			msg= "你上传的文件总大小超出了最大限制（5M）"
	end select
	set upload=nothing
	Call Error(msg)
end if

SavePath = "../../wml/"
content=upload.form("content")

if len(content)>30 then
	Call Error("命名最多30字，请返回重试！")
end if


for each formName in upload.file
	set ofile=upload.file(formName)  '生成一个文件对象
	upfilename=ofile.FileName
	oFileSize=ofile.filesize
	sizes=cstr(round(oFileSize/1024))
	fileExt=lcase(ofile.FileExt)

	if fileEXT<>"wml" then
		EnableUpload=false
	end if
	if EnableUpload=false then
		msg="这种文件类型不允许上传:asp|asa|aspx|exe|bat|..."
		FoundErr=true
		set ofile=nothing
		set upload=nothing
		call error("只支持WML格式文件！"&fileExt)
	end if
	if oFileSize>(MaxFileSize*1024) then
		msg="文件大小超过了限制，最大只能上传" & CStr(MaxFileSize) & "K的文件！"
		FoundErr=true
		msg=msg & "<br/><a href=""wmltext.asp?sid="&sid&""">返回上级</a><br/>"
		set ofile=nothing
		set upload=nothing
		Call error(msg)
	end if


	if FoundErr<>true then
		randomize
		ranNum=int(900*rnd)+100

		strMonth=month(time_now)
		if len(strMonth)=1 then
			strMonth="0"&strMonth
		end if
		strDay=day(time_now)
		if len(strDay)=1 then
			strDay="0"&strDay
		end if

		dim wmlname

		if Content<>"" Then
			wmlname=Content
		else
			wmlname=year(time_now)&strMonth&strDay&hour(time_now)&minute(time_now)&second(time_now)&ranNum
		end if

		filename=SavePath&wmlname&"."&fileExt

		dim realpath
		realpath=filename

		ofile.SaveToFile Server.mappath(realpath)   '保存文件

	END IF
next
set upload=nothing

msg="上传WML文件成功！文件名称为"&realpath&"<br/><a href=""wmltext.asp?sid="&sid&""">WML页面管理</a><br/>"

%>
<%=msg%>
<a href="index.asp?sid=<%=sid%>">[站长工具]</a><%Call Last2%>